package main

import (
	"fmt"
	"math/rand"
	"sort"
)

var (
	size          int = 100
	maxValue      int = 100
	times         int = 500000
	notEqualTimes int = 0
)

func main() {

	for i := 1; i <= times; i++ {
		arr := generateArray(size, maxValue)
		goSort(arr)
		arr2 := copyArray(arr)
		insertSort(arr2)
		equal := isEqual(arr, arr2)
		if !equal {
			notEqualTimes++
		}
	}
	fmt.Println(notEqualTimes)

}

func insertSort(arr []int) {
	for i := 1; i < len(arr); i++ {
		for j := i; j > 0; j-- {
			if arr[j-1] > arr[j] {
				arr[j-1], arr[j] = arr[j], arr[j-1]
			}
		}
	}
}

func goSort(arr []int) {
	sort.Ints(arr)
}

func generateArray(size, maxValue int) []int {
	var array []int = make([]int, size)
	for i := 0; i < size; i++ {
		array = append(array, rand.Intn(maxValue*2)-maxValue)
	}
	return array
}

func copyArray(arr []int) []int {
	var temp []int = make([]int, len(arr))
	copy(temp, arr)
	return temp
}

func isEqual(arr1, arr2 []int) (equal bool) {
	if len(arr1) != len(arr2) {
		equal = false
		return
	}
	for i := 0; i < len(arr1); i++ {
		if arr1[i] != arr2[i] {
			equal = false
			return
		}
	}
	equal = true
	return
}
